package com.example.springbootjasyptdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author chaird
 * @create 2022-08-13 22:50
 */
@RestController
public class HelloController implements EnvironmentAware {

  private Environment environment;

  @Autowired private JdbcTemplate jdbcTemplate;

  @GetMapping("/hello")
  public Object jdbcDemo() {
    List<Map<String, Object>> maps = jdbcTemplate.queryForList("select  * from student");
    return maps;
  }


  @GetMapping("/env")
  public String env() {
    String property = environment.getProperty("spring.datasource.password");
    return property;
  }

  @Override
  public void setEnvironment(Environment environment) {
    this.environment = environment;
  }
}
